﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EBAYVN.DAO;
using EBAYVN.DOMAIN;
namespace EBAYVN.Share
{
    public partial class Header : System.Web.UI.UserControl
    {
        private EbayFuntionDao dao = new EbayFuntionDao();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadMenu();
            }
        }
        private void LoadMenu()
        {
            var list = dao.GetList(0);
            rpParent.DataSource = list;
            rpParent.DataBind();
        }

        protected void rpParent_DataBound(object sender, RepeaterItemEventArgs e)
        {
            if (!e.Item.ItemType.Equals(ListItemType.Item) &&
                !e.Item.ItemType.Equals(ListItemType.AlternatingItem)) return;

            var item = (BiddingFuntion)(e.Item.DataItem);
            if (item == null) return;
            var list = dao.GetList(item.Id);

            var child = (Repeater)e.Item.FindControl("rpChild");

            if (child == null) return;
            if (list.Count != 0)
            {
                child.DataSource = list;
                child.DataBind();
            }

            //if (list.Count == 0)
            //    e.Item.Visible = false;
        }
    }
}